<template>
	<uv-tabs :scrollable="false" lineColor="#fe536f" :activeStyle="{color: '#222',fontWeight: 'bold'}" :inactiveStyle="{
			color: '#999'}" :list="list" @click="click"></uv-tabs>
	<view class="padding_30" style="padding-top: 0;">
		<view v-if="currentIndex==0" @click="todetail">
			<FriendList :list="favoriteTasksList" type="usermark"></FriendList>
			<uv-load-more :status="taskloadStatus" />
		</view>
		<view v-if="currentIndex==1">
			<!-- 瀑布流布局 -->
			<view>
				<ReleaseActiveList :list="favoriteActivityList" ishome="home"></ReleaseActiveList>
				<uv-load-more :status="loadStatus" />
			</view>
		</view>

	</view>
</template>

<script setup>
	import { ref, reactive } from 'vue';
	import { onLoad, onReachBottom } from "@dcloudio/uni-app";
	import { useUserStore } from '@/store/modules/user.js'
	import FriendList from '@/components/FriendList.vue';
	import ReleaseActiveList from '@/components/ReleaseActiveList.vue';
	const userstore = useUserStore()
	const currentIndex = ref(0)
	const page = ref(1)
	const loadStatus = ref('loadmore')
	const taskloadStatus = ref('loadmore')
	const favoriteActivityList = ref([]) //收藏活动列表
	const favoriteTasksList = ref([]) //收藏找伴列表
	const list = reactive([{
		name: '收藏的找伴'
	}, {
		name: '收藏的活动',
	}])
	onLoad(() => {
		page.value = 1
		favoriteActivityList.value = []
		favoriteTasksList.value = []
		getFavoriteActivityList()
		getFavoriteTasksList()
	})
	onReachBottom(() => {
		if (currentIndex.value == 0) {
			if (loadStatus.value == 'nomore') {
				return uni.$uv.toast('没有更多了~')
			}
			page.value++
			getFavoriteActivityList()
		} else {
			if (taskloadStatus.value == 'nomore') {
				return uni.$uv.toast('没有更多了~')
			}
			page.value++
			getFavoriteTasksList()
		}
	})
	// 切换tab
	const click = (item) => {
		currentIndex.value = item.index
		page.value = 1
		favoriteActivityList.value = []
		favoriteTasksList.value = []
		getFavoriteActivityList()
		getFavoriteTasksList()
	}
	const todetail = () => {
		uni.navigateTo({
			url: '/pages/activeDetail/detail/index'
		})
	}
	// 获取收藏活动列表
	const getFavoriteActivityList = async () => {
		loadStatus.value = 'loading'
		let res = await userstore.getFavoriteActivityList({
			lat: uni.getStorageSync('latitude'),
			lng: uni.getStorageSync('longitude'),
			page: page.value
		})
		if (res.code == 200 && res.data) {
			favoriteActivityList.value = favoriteActivityList.value.concat(res.data.data)
			// 判断是否还有数据
			if (res.data.current_page >= res.data.last_page) {
				loadStatus.value = 'nomore'
			} else {
				loadStatus.value = 'loadmore'
			}
		} else {
			loadStatus.value = 'nomore'
		}
	}
	// 获取收藏找伴列表
	const getFavoriteTasksList = async () => {
		taskloadStatus.value = 'loading'
		let res = await userstore.getFavoriteTasksList({
			lat: uni.getStorageSync('latitude'),
			lng: uni.getStorageSync('longitude'),
			page: page.value
		})
		if (res.code == 200 && res.data) {
			favoriteTasksList.value = favoriteTasksList.value.concat(res.data.data)
			// 判断是否还有数据
			if (res.data.current_page >= res.data.last_page) {
				taskloadStatus.value = 'nomore'
			} else {
				taskloadStatus.value = 'loadmore'
			}
		} else {
			taskloadStatus.value = 'nomore'
		}
	}
</script>
<style>
	page {
		background-color: #F6F6F6;
	}
</style>